package com.ktjy.web.servlet;

import com.ktjy.web.entity.AjaxResult;
import com.ktjy.web.entity.OrderList;
import com.ktjy.web.service.OrderService;
import com.ktjy.web.service.impl.OrderServiceImpl;

import my.framework.anno.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class OrdersServlet{
    @RequestMapping("/order")
    public Object order(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");

        String opr = request.getParameter("opr");
        String order_id = request.getParameter("order_id");
        OrderService ordersService = new OrderServiceImpl();
        if("list".equals(opr)){
            List<OrderList> list = ordersService.selectAll();
            return AjaxResult.success("执行成功",list);
        }else if("find".equals(opr)){
            List<OrderList> list = ordersService.selectById(Integer.valueOf(order_id));
            return AjaxResult.success("执行成功",list);
        }
        return null;
    }
}
